home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 October: Mac OS SDK / Dev.CD Oct 96 SDK / Dev.CD Oct 96 SDK2.toast / Development Kits (Disc 2) / OpenDoc Development Framework / ODFDev / Embed / Sources / Part.cpp < prev    next >
Encoding:
Text File  |  1996-08-16  |  5.5 KB  |  212 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                Part.cpp
  4. //    Release Version:    $ ODF 1 $
  5. //
  6. //    Author:                M.Boetcher
  7. //
  8. //    Copyright:    (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  9. //
  10. //========================================================================================
  11.  
  12. #include "Embed.hpp"
  13.  
  14. #ifndef PART_H
  15. #include "Part.h"
  16. #endif
  17.  
  18. #ifndef BINDING_K
  19. #include "Binding.k"
  20. #endif
  21.  
  22. #ifndef DEFINES_K
  23. #include "Defines.k"
  24. #endif
  25.  
  26. #ifndef SELECT_H
  27. #include "Select.h"
  28. #endif
  29.  
  30. #ifndef PROXY_H
  31. #include "Proxy.h"
  32. #endif
  33.  
  34. #ifndef FRAME_H
  35. #include "Frame.h"
  36. #endif
  37.  
  38. #ifndef CONTENT_H
  39. #include "Content.h"
  40. #endif
  41.  
  42. // ----- ODF -----
  43.  
  44. #ifndef FWABOUT_H
  45. #include "FWAbout.h"
  46. #endif
  47.  
  48. #ifndef FWSUSINK_H
  49. #include "FWSUSink.h"
  50. #endif
  51.  
  52. #ifndef FWCFMRES_H
  53. #include "FWCFMRes.h"
  54. #endif
  55.  
  56. // ----- OpenDoc Includes -----
  57.  
  58. #ifndef SOM_Module_OpenDoc_Commands_defined
  59. #include <CmdDefs.xh>
  60. #endif
  61.  
  62. #ifndef SOM_Module_OpenDoc_StdProps_defined
  63. #include <StdProps.xh>
  64. #endif
  65.  
  66. //========================================================================================
  67. //    Runtime information
  68. //========================================================================================
  69.  
  70. #ifdef FW_BUILD_MAC
  71. #pragma segment odfembed
  72. #endif
  73.  
  74. FW_DEFINE_AUTO(CEmbedPart)
  75.  
  76. //========================================================================================
  77. //    CLASS CEmbedPart
  78. //========================================================================================
  79.  
  80. #define kMainPresentation "Apple:Presentation:EmbedPart"
  81.  
  82. //----------------------------------------------------------------------------------------
  83. //     CEmbedPart constructor
  84. //----------------------------------------------------------------------------------------
  85.  
  86. CEmbedPart::CEmbedPart(ODPart* odPart):
  87.     FW_CEmbeddingPart(odPart, FW_gInstance, kPartInfoID),
  88.     fPresentation(NULL),
  89.     fEmbedContent(NULL),
  90.     fFacetNumber(cOneFacet)
  91. {
  92.     // Do not call anything that can fail
  93. }
  94.  
  95. //----------------------------------------------------------------------------------------
  96. //     CEmbedPart::Initialize
  97. //----------------------------------------------------------------------------------------
  98.  
  99. void CEmbedPart::Initialize(Environment* ev)
  100. {
  101.     FW_CEmbeddingPart::Initialize(ev);
  102.  
  103.     // Create the presentation and selection objects.
  104.     // The selection object is actually owned by the presentation
  105.     CEmbedSelection* selection = FW_NEW(CEmbedSelection, (ev, fEmbedContent));
  106.     fPresentation = RegisterPresentation(ev, kMainPresentation, true, selection);
  107.  
  108.     // ----- Initialize my menu -----
  109.     GetMenuBar(ev)->InitializeFromResource(ev, kMenuBar);
  110. }
  111.  
  112. //----------------------------------------------------------------------------------------
  113. //     CEmbedPart destructor
  114. //----------------------------------------------------------------------------------------
  115.  
  116. CEmbedPart::~CEmbedPart()
  117. {
  118. }
  119.  
  120. //----------------------------------------------------------------------------------------
  121. //    CEmbedPart::NewPartContent
  122. //----------------------------------------------------------------------------------------
  123.  
  124. FW_CContent* CEmbedPart::NewPartContent(Environment* ev)
  125. {
  126.     fEmbedContent = FW_NEW(CEmbedContent, (ev, this));
  127.     return fEmbedContent;
  128. }
  129.  
  130. //----------------------------------------------------------------------------------------
  131. //     CEmbedPart::NewFrame
  132. //----------------------------------------------------------------------------------------
  133.  
  134. FW_CFrame* CEmbedPart::NewFrame(Environment* ev, 
  135.                                 ODFrame* odFrame, 
  136.                                 FW_CPresentation* presentation, 
  137.                                 FW_Boolean fromStorage)
  138. {
  139. FW_UNUSED(presentation);
  140. FW_UNUSED(fromStorage);
  141.     
  142.     return FW_NEW(CEmbedFrame, (ev, odFrame, presentation, this, fEmbedContent));
  143. }
  144.  
  145. //----------------------------------------------------------------------------------------
  146. // CEmbedPart::DoAdjustMenus
  147. //----------------------------------------------------------------------------------------
  148.  
  149. FW_Boolean CEmbedPart::DoAdjustMenus(Environment* ev, 
  150.                                     FW_CMenuBar* menuBar, 
  151.                                     FW_Boolean hasMenuFocus,
  152.                                     FW_Boolean isRoot)
  153. {
  154.     if (hasMenuFocus)
  155.     {
  156.         FW_Boolean hasProxy = (fEmbedContent->GetProxy() != NULL);
  157.         FW_Boolean oneFacet = (fFacetNumber == cOneFacet);
  158.         
  159.         menuBar->EnableAndCheckCommand(ev, cOneFacet, hasProxy, oneFacet);
  160.         menuBar->EnableAndCheckCommand(ev, cFourFacets, hasProxy, !oneFacet);
  161.     }
  162.     
  163.     return FALSE;
  164. }
  165.  
  166. //----------------------------------------------------------------------------------------
  167. // CEmbedPart::DoMenu
  168. //----------------------------------------------------------------------------------------
  169.  
  170. FW_Boolean CEmbedPart::DoMenu(Environment* ev, const FW_CMenuEvent& theMenuEvent)
  171. {
  172.     FW_Boolean menuHandled = TRUE;
  173.     ODCommandID id = theMenuEvent.GetCommandID(ev);
  174.     
  175.     switch (id)
  176.     {
  177.         case cOneFacet:
  178.         case cFourFacets:
  179.             ChangeEmbeddedFacets(ev, id);
  180.             break;
  181.         
  182.         case kODCommandAbout:
  183.             ::FW_About(ev, this, kAbout);
  184.             break;
  185.  
  186.         default:
  187.             menuHandled = FALSE;
  188.     }
  189.     
  190.     return menuHandled;
  191. }
  192.  
  193. //----------------------------------------------------------------------------------------
  194. //     CEmbedPart::ChangeEmbeddedFacets
  195. //----------------------------------------------------------------------------------------
  196.  
  197. void CEmbedPart::ChangeEmbeddedFacets(Environment* ev, ODCommandID facetNumber)
  198. {
  199.     if (fFacetNumber != facetNumber)
  200.     {
  201.         CEmbedProxy* proxy = fEmbedContent->GetProxy();
  202.         FW_ASSERT(proxy);
  203.         
  204.         proxy->HideShow(ev, FALSE);            // hide will remove all the facets    
  205.         fFacetNumber = facetNumber;
  206.         proxy->HideShow(ev, TRUE);            // Show will recreate the facets    
  207.     
  208.         fPresentation->Invalidate(ev);
  209.     }
  210. }
  211.  
  212.